﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

public class TaskLogic
{
    private static TaskLogic self;
    private ModelLocator model;
    /// <summary>
    /// 当前任务表
    /// </summary>
    private string _curtTaskLablName = "Task_Accepted";
    /// <summary>
    /// 任务进度表
    /// </summary>
    private string _taskRecord = "Task_Record";

    public static TaskLogic getInstance()
    {
        if (self == null)
        {
            self = new TaskLogic();
        }
        return self;
    }

    public TaskLogic()
    {
        init();
    }

    private void init()
    {
        model = ModelLocator.getInstance();
    }

    /// <summary>
    /// 获得任务信息表 
    /// </summary>
    public Record getTaskInfoRec()
    {
        return model.scene.GetRecordEx(_curtTaskLablName);
    }

    /// <summary>
    /// 获得任务进度表
    /// </summary>
    public Record getTaskProgressRec()
    {
        return model.scene.GetRecordEx(_taskRecord);
    }


    /// <summary>
    /// 获得接取任务具体内容
    /// </summary>
    public ArrayList getTaskInfo(int taskId)
    {
        Record taskInfoRec = getTaskInfoRec();
        ArrayList taskInfo = new ArrayList();

        int tSize = taskInfoRec.recArr.Count;

        for (int i = 0; i < tSize; i++)
        {
            ArrayList arrLine = (ArrayList)taskInfoRec.recArr[i];
            ArrayList arr = (ArrayList)arrLine[0];
            if ((int)arr[0] == taskId)
            {
                taskInfo = arr;
                break;
            }
        }
        return taskInfo;
    }

    /// <summary>
    /// 获得任务具体进度内容
    /// </summary>
    public ArrayList getTaskProgress(int taskId)
    {
        Record taskProgressRec = getTaskInfoRec();
        ArrayList taskProgress = new ArrayList();

        int tSize = taskProgressRec.recArr.Count;

        for (int i = 0; i < tSize; i++)
        {
            ArrayList arrLine = (ArrayList)taskProgressRec.recArr[i];
            ArrayList arr = (ArrayList)arrLine[0];

            if ((int)arr[0] == taskId)
            {
                taskProgress = arr;
                break;
            }
        }
        return taskProgress;

    }

    /// <summary>
    /// 用于区分任务的类型显示（主:xxxx;支:xxxx）
    /// </summary>
    public string getTaskTypeDisp(string taskName, string type)
    {
        string tmpStr = "";
        switch (type)
        {
            case "1-1":
                tmpStr = BinaryReaderTool.getInstance().getSwfLangStrVar("UIStr_1000449", taskName);
                break;
            case "1-10":
                tmpStr = BinaryReaderTool.getInstance().getSwfLangStrVar("UIStr_1000450", taskName);
                break;
            default:
                tmpStr = taskName;
                break;
        }
        return tmpStr;
    }

    /// <summary>
    /// 获取任务显示优先级(用于显示先后顺序)
    /// </summary>
    public int getTaskTypeKey(string type)
    {
        int key = 0;
        switch (type)
        {
            case "1-1":
                key = 3;
                break;
            case "1-10":
                key = 2;
                break;
            default:
                key = 0;
                break;
        }
        return key;
    }


}